$("#update").click(function(){
		var width=$(document).width();
		var height=$(document).height();
		$('#opacity').css('width',width+'px');
		$('#opacity').css('height',height+'px');
		$('#opacity').css('display','block');
		$('#opacity').css('opacity','0.5');
		$('#image_loadder').css('display','block');
		$('#image_loadder').css("left",($(window).width()-100)/2+"px");
		$('#image_loadder').css("top",($(window).height()-100)/2+"px");
		setTimeout(function(){
			window.location = location.href;
		},60000);
		$.get(
				'/update',
				{name:domain},
				function(data)
				{
					window.location = location.href;
				}
		);
	});
$(document).ready(function(){
	$(".result").html("<img src='/images/loadder.gif'/>");
	$(".time").html("<img src='/images/loadder.gif'/>");
	$.get(
			'/spot_check_appengine',
			{name:domain},
			function(data)
			{
				if(data != "0")
				{
					$("#result_app").html("Ok");
					$("#time_app").html(data);
				} else {
					$("#result_app").html("False");
					$("#time_app").html("0");
				}
			}
	);
	$.get(
			'/spot_check_us',
			{name:domain},
			function(data)
			{
				if(data != "0")
				{
					$("#result_us").html("Ok");
					$("#time_us").html(data);
				} else {
					$("#result_us").html("False");
					$("#time_us").html("0");
				}
			}
	);
	$.get(
			'/spot_check_canada',
			{name:domain},
			function(data)
			{
				if(data != "0")
				{
					$("#result_canada").html("Ok");
					$("#time_canada").html(data);
				} else {
					$("#result_canada").html("False");
					$("#time_canada").html("0");
				}
			}
	);
	$.get(
			'/spot_check_vietnam',
			{name:domain},
			function(data)
			{
				if(data != "0")
				{
					$("#result_vietnam").html("Ok");
					$("#time_vietnam").html(data);
				} else {
					$("#result_vietnam").html("False");
					$("#time_vietnam").html("0");
				}
			}
	);
});
var URL_TO_GET_RESULTS_FOR = "http://"+domain;
//Specify your actual API key here:
var API_KEY = 'AIzaSyB-aMH9_2JJCYCSRL578Vnqiio6faclchE';

var API_URL = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?';
var CHART_API_URL = 'http://chart.apis.google.com/chart?';

//Object that will hold the callbacks that process results from the
//Page Speed Online API.
var callbacks = {}

//Invokes the Page Speed Online API. The response will contain
//JavaScript that invokes our callback with the Page Speed results.
function runPagespeed() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
var query = [
 'url=' + URL_TO_GET_RESULTS_FOR,
 'callback=runPagespeedCallbacks',
 'key=' + API_KEY,
].join('&');
s.src = API_URL + query;
document.getElementsByTagName("head")[0].insertBefore(s, null);
document.getElementById("page_speed").children[0].innerHTML = "Loading ...";
}

//Our JSONP callback. Checks for errors, then invokes our callback handlers.
function runPagespeedCallbacks(result) {
if (result.error) {
 var errors = result.error.errors;
 for (var i = 0, len = errors.length; i < len; ++i) {
   if (errors[i].reason == 'badRequest' && API_KEY == 'AIzaSyB-aMH9_2JJCYCSRL578Vnqiio6faclchE') {
     alert('Please specify your Google API key in the API_KEY variable.');
   } else {
     // NOTE: your real production app should use a better
     // mechanism than alert() to communicate the error to the user.
     alert(errors[i].message);
   }
 }
 return;
}

// Dispatch to each function on the callbacks object.
for (var fn in callbacks) {
 var f = callbacks[fn];
 if (typeof f == 'function') {
   callbacks[fn](result);
 }
}
}

callbacks.displayPageSpeedScore = function(result) {
var score = result.score;
// Construct the query to send to the Google Chart Tools.
var query = [
 'chtt=Page+Speed+score:+' + score,
 'chs=180x100',
 'cht=gom',
 'chd=t:' + score,
 'chxt=x,y',
 'chxl=0:|' + score,
].join('&');
var i = document.createElement('img');
i.src = CHART_API_URL + query;
document.getElementById("page_speed").insertBefore(i, null);
};

var RESOURCE_TYPE_INFO = [
{label: 'JavaScript', field: 'javascriptResponseBytes', color: 'e2192c'},
{label: 'Images', field: 'imageResponseBytes', color: 'f3ed4a'},
{label: 'CSS', field: 'cssResponseBytes', color: 'ff7008'},
{label: 'HTML', field: 'htmlResponseBytes', color: '43c121'},
{label: 'Flash', field: 'flashResponseBytes', color: 'f8ce44'},
{label: 'Text', field: 'textResponseBytes', color: 'ad6bc5'},
{label: 'Other', field: 'otherResponseBytes', color: '1051e8'},
];

callbacks.displayResourceSizeBreakdown = function(result) {
var stats = result.pageStats;
var labels = [];
var data = [];
var colors = [];
var totalBytes = 0;
var largestSingleCategory = 0;
for (var i = 0, len = RESOURCE_TYPE_INFO.length; i < len; ++i) {
 var label = RESOURCE_TYPE_INFO[i].label;
 var field = RESOURCE_TYPE_INFO[i].field;
 var color = RESOURCE_TYPE_INFO[i].color;
 if (field in stats) {
   var val = Number(stats[field]);
   totalBytes += val;
   if (val > largestSingleCategory) largestSingleCategory = val;
   labels.push(label);
   data.push(val);
   colors.push(color);
 }
}
// Construct the query to send to the Google Chart Tools.
var query = [
 'chs=300x140',
 'cht=p3',
 'chts=' + ['000000', 16].join(','),
 'chco=' + colors.join('|'),
 'chd=t:' + data.join(','),
 'chdl=' + labels.join('|'),
 'chdls=000000,14',
 'chp=1.6',
 'chds=0,' + largestSingleCategory,
].join('&');
var i = document.createElement('img');
i.src = 'http://chart.apis.google.com/chart?' + query;
document.getElementById("page_speed").insertBefore(i, null);
document.getElementById("page_speed").children[0].style.display = "none";
};